home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / New System Software Extensions / QuickDraw™ GX 1.1.2 / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / CustomWriter GX 1.0.3 ƒ / OldApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  5.8 KB  |  190 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         OldApp.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for our old-application message overrides.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         06/14/95 - Dave Hersey -    Version 1.0.3 to fix a bug in
  14.                                     CustomBufferingAndIO.c when creating
  15.                                     high-res PICTs, and to make the size
  16.                                     of buffers more flexible.
  17.  
  18.         05/26/95 - Dave Hersey -    Version 1.0.2 to add the new 'outp'
  19.                                     desktop printer resource in NewApp.c.
  20.  
  21.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  22.                                     CustomBufferingAndIO.c.
  23.  
  24.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  25.                                     ImageWriter driver.
  26.  
  27.     NOTE: Relevant goodies are listed in MPW's "Mark" menu.
  28.  
  29. */
  30.  
  31. #include "CommonDefines.h"
  32.  
  33.  
  34. /*    -----------------------------------------------------------------------
  35.  
  36.     SD_ConvertPrintRecordTo is an override of gxConvertPrintRecordTo.  It
  37.     takes a print record in old style (driver specific) format, and converts
  38.     it to the format of gxUniversalPrintRecordHdl.  Since we don't have an
  39.     "old-style" format we need to support, there's not much we need to do
  40.     here.
  41.  
  42.     -----------------------------------------------------------------------    */
  43.  
  44. OSErr SD_ConvertPrintRecordTo(THPrint hoPrint)
  45. {
  46.     TPPrint                        poPrint;            // pointer to old style print record
  47.     gxUniversalPrintRecordHdl    huPrint = (gxUniversalPrintRecordHdl) hoPrint;    // handle to universal print record
  48.     gxUniversalPrintRecordPtr    puPrint;            // pointer to universal print record
  49.     short                        wDev;                // cached wDev
  50.  
  51.     puPrint = *huPrint;
  52.     poPrint = *hoPrint;
  53.  
  54.     // We always print at our best resolution, and autofeed at 100% scaling.
  55.  
  56.     puPrint->qualityMode = gxBestQuality;
  57.     puPrint->feed =    true;
  58.     puPrint->reduction = 100;
  59.  
  60.     // Save our orientation and copies settings.
  61.     wDev = poPrint->prStl.wDev;
  62.     puPrint->orientation = (wDev & kPortrait)?    gxPortraitOrientation: gxLandscapeOrientation;
  63.     puPrint->actualCopies =    poPrint->prJob.iCopies;
  64.     puPrint->options = 0;
  65.         
  66.     return noErr;
  67. }
  68.  
  69.  
  70. /*    -----------------------------------------------------------------------
  71.  
  72.     SD_ConvertPrintRecordFrom is an override for gxConvertPrintRecordFrom.
  73.     It takes a print record in universal format and converts it to old
  74.     style (driver specific) format.  Since we don't have an "old-style"
  75.     format we need to support, there's not much we need to do here.
  76.  
  77.     -----------------------------------------------------------------------    */
  78.  
  79. OSErr SD_ConvertPrintRecordFrom(gxUniversalPrintRecordHdl huPrint)
  80. {
  81.     gxUniversalPrintRecordPtr    puPrint;            // pointer to universal print record
  82.     THPrint                        hoPrint = (THPrint) huPrint;    // handle to old style print record
  83.     TPPrint                        poPrint;            // pointer to old style print record
  84.     short                        wDev;                // workspace to create our wDev value
  85.  
  86.     // Cache pointers for size and speed
  87.     puPrint = *huPrint;
  88.     poPrint = *hoPrint;
  89.  
  90.     // Convert various fields of our print record, starting with the wDev.
  91.     
  92.     // This is our base wDev value-- note I was bad and didn't register this
  93.     // with DEVSUPPORT.  You should.
  94.  
  95.     wDev = kDriverWDev;
  96.     
  97.     if (puPrint->orientation == gxPortraitOrientation)
  98.         wDev |= kPortrait;
  99.  
  100.     poPrint->prStl.wDev            = wDev;
  101.     poPrint->iPrVersion            = kPrintRecordVers;
  102.     poPrint->prInfo.iDev        = 0;
  103.     poPrint->prInfoPT.iDev         = 0;
  104.     poPrint->prStl.bPort         = 0;
  105.     poPrint->prStl.feed         = false;
  106.     poPrint->prJob.iCopies        = puPrint->actualCopies;
  107.     poPrint->prJob.bJDocLoop    = 1;
  108.     
  109.     // This routine is so studly, there can be no errors
  110.     return noErr;    
  111. }
  112.  
  113.  
  114. /*    -----------------------------------------------------------------------
  115.  
  116.     SD_PrValidate is an override of gxPrValidate.  It validates the current
  117.     print record.  It's fairly simplistic--if the wDev or versions don't
  118.     match ours, we call PrintDefault.  Otherwise, we call UpdatePrintRecord
  119.     to allow the driver to sanity check any internal fields.
  120.  
  121.     -----------------------------------------------------------------------    */
  122.  
  123. OSErr SD_PrValidate(THPrint hPrint,         // old style print record
  124.                     Boolean *wasChanged)    // was the print record changed?
  125. {
  126.     unsigned short    wDev;
  127.     Boolean            recordIsInvalid = true;            
  128.     OSErr            anErr = noErr;
  129.  
  130.     // Check the wDev.  The upper byte must be equal to our wDev
  131.         
  132.     wDev = (*hPrint)->prStl.wDev;    
  133.     wDev >>= 8;                        // Get just the device ID
  134.  
  135.     // If the device id is equal to ours, check the version number of the print record.
  136.     // Only if that is also equal to the current version, will we return false (valid).
  137.         
  138.     if ((wDev == (kDriverWDev >> 8)) && ((((*hPrint)->iPrVersion) == kPrintRecordVers)))
  139.         recordIsInvalid = false;
  140.  
  141.     // If the print record is not valid, then call PrintDefault so
  142.     // that QuickDraw GX loads our default print record from 'PREC' 0.
  143.     // Otherwise, do the final sanity check/reset of our print record.
  144.         
  145.     if (recordIsInvalid)
  146.         PrintDefault(hPrint);
  147.     else
  148.         anErr = UpdatePrintRecord(hPrint);
  149.         
  150.     *wasChanged = recordIsInvalid;
  151.     return (anErr);
  152. }
  153.  
  154.  
  155. /*    -----------------------------------------------------------------------
  156.  
  157.     UpdatePrintRecord is called by SD_PrValidate.  It simply does a sanity
  158.     check (and reset) of the volatile fields of our old style print records.
  159.  
  160.     -----------------------------------------------------------------------    */
  161.  
  162. OSErr UpdatePrintRecord(THPrint hPrint)
  163. {
  164.     OSErr                        anErr;
  165.     gxUniversalPrintRecordHdl     huPrint = (gxUniversalPrintRecordHdl) hPrint;
  166.     gxUniversalPrintRecordPtr     puPrint;
  167.  
  168.     // Convert the print record to universal format.  If there are
  169.     // no errors, store the resolution, and convert the print
  170.     // record back to non-universal format.
  171.  
  172.     anErr = SD_ConvertPrintRecordTo(hPrint);
  173.  
  174.     if (anErr == noErr)
  175.     {
  176.         puPrint = *huPrint;
  177.  
  178.         // Default the app & device resolutions
  179.         puPrint->devVRes =
  180.         puPrint->devHRes =
  181.         puPrint->appVRes =
  182.         puPrint->appHRes = 72;
  183.         
  184.         // Convert back to non-universal format
  185.         anErr = SD_ConvertPrintRecordFrom((gxUniversalPrintRecordHdl) hPrint);
  186.     }
  187.         
  188.     return anErr;
  189. }
  190.